#!/bin/bash
user=www
group=nginx
deploy_key="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyR/eodBFoRmMtofW52Ie6TKfEkii+F/o2OBParoM7ryQin6aWdw/Un5dg+fm3lhT9QSeNphjEhD0hNNBnyRD1N9UyjuWjwoeNftIbWvAvJfaOH5rawG1Qj82XVo5Pf/6savONuCFPx4bxOBxDGpCQm6drcXheUo0ZGf5DAqi9C2mtpGmhVtGV7BWKAP9GA1w5Fs22k2OoNj5MZ0mFHbYqPtivrTLVydB2SqVopDVACYN2HvO1HyJDdVUPDoj5fX2oI7vKqr0B4JarAkvTd42UFO2RiznQD5JB5dtu+/IsaU5v3hRJbKEHeQ9XQgwmtry4OIlQJV+Zqdg1dUX4ovxVQ== 168-www"
wwwroot_path=/data/wwwroot
deploy_path=/data/path

if [ `whoami` != "root" ];then
    echo "请使用 root 用户执行该脚本"
    exit 1
fi

# 添加用户
if ! (id -u $user >& /dev/null )
then
    useradd $user
fi

usermod -aG $group $user;

# 添加 deploy key
if [ ! -d /home/$user/.ssh ]
then
    mkdir -p /home/$user/.ssh
fi

echo $deploy_key > /home/$user/.ssh/authorized_keys
chmod 700 /home/$user/
chmod 644 /home/$user/.ssh/authorized_keys
chown -R $user:$group /home/$user


if [ ! -d /data ]
then
    mkdir /data
fi

if [ ! -d $wwwroot_path ]
then
    mkdir $wwwroot_path
    chown -R $user:$group $wwwroot_path
fi

if [ ! -d $deploy_path ]
then
    mkdir $deploy_path
fi

